function loadOrder() {

    var checkTag = $(".secfirst").find('a').text();
    $.ajax({
        url : "/DrivingMan/orderInfo/getMyOrder.do",
        type : "post",
        data : {
            "checkTag" : checkTag
        },
        dataType : "json",
        success : function(result) {

            if (result.status == "0000") {
                var orderInfo = result.data;
                for ( var i = 0; i < orderInfo.length; i++) {
                    var order = orderInfo[i];
                    var order_status = order.order_status;
                    var order_id = order.order_id;
                    var car_info = order.car_info;
                    var order_time = order.order_time;
                    var return_time = order.return_time;
                    if (order_status == "0") {
                        var tbody = '<tr>' + '<td>' + order_id + '</td>' + '<td>' + car_info + '</td>' + '<td>'
                                + order_time + '</td>' + '<td>' + return_time + '</td>' + '<td>待接单</td>'
                                + '<td>等待接单</td>' + '</tr>';
                    }
                    else if (order_status == "1") {
                        var tbody = '<tr>' + '<td>' + order_id + '</td>' + '<td>' + car_info + '</td>' + '<td>'
                                + order_time + '</td>' + '<td>' + return_time + '</td>' + '<td>进行中</td>'
                                + '<td><input type="button" id="returncar" onclick="returncar(' + order_id
                                + ')" value="还车"/></td>' + '</tr>';
                    }
                    else if (order_status == "2") {
                        var tbody = '<tr>' + '<td>' + order_id + '</td>' + '<td>' + car_info + '</td>' + '<td>'
                                + order_time + '</td>' + '<td>' + return_time + '</td>' + '<td>已还车</td>'
                                + '<td><input type="button" id="writetest" onclick="writetest(' + order_id
                                + ')" value="试驾体验"/></td>' + '</tr>';
                    }
                    else if (order_status == "3") {
                        var tbody = '<tr>' + '<td>' + order_id + '</td>' + '<td>' + car_info + '</td>' + '<td>'
                                + order_time + '</td>' + '<td>' + return_time + '</td>' + '<td>已完成</td>'
                                + '<td>已完成</td>' + '</tr>';
                    }
                    else if (order_status == "4") {
                        var tbody = '<tr>' + '<td>' + order_id + '</td>' + '<td>' + car_info + '</td>' + '<td>'
                                + order_time + '</td>' + '<td>' + return_time + '</td>' + '<td>无效订单</td>'
                                + '<td>订单超时或拒绝</td>' + '</tr>';
                    }
                    $("#myorderbody").append(tbody);
                }
            }
            else {
                alert("未查询到订单信息！");
            }
        }
    });
}
function getAllOrder(a) {

    $("#myorderbody").empty();
    var s = document.getElementById("mydriveinfo");
    s.style.display = "none";
    var l = document.getElementById("orderinfo");
    l.style.display = "block";
    $(".first").attr("class", "");
    var $a = $(a);
    $a.parent().attr("class", "first");
    loadOrder();
}

function getAllOrderBy(a) {

    $("#myorderbody").empty();
    $(".secfirst").attr("class", "");
    var $a = $(a);
    $a.parent().attr("class", "secfirst");
    loadOrder();
}
function getMyDrive(a) {

    $("#travelList").empty();
    var s = document.getElementById("mydriveinfo");
    s.style.display = "block";
    var l = document.getElementById("orderinfo");
    l.style.display = "none";
    $(".first").attr("class", "");
    var $a = $(a);
    $a.parent().attr("class", "first");
    var testTag = null;
    var userid = getCookie("userId");
    $.ajax({
        url : "/DrivingMan/exp/showTestList.do",
        type : "post",
        data : {
            "testTag" : testTag,
            "userid" : userid
        },
        dataType : "json",
        success : function(result) {

            var testList = result.data;
            for ( var i = 0; i < testList.length; i++) {
                var art_id = testList[i].article_id;
                var art_title = testList[i].article_title;
                var user_name = testList[i].user_name;
                var time = testList[i].article_time;
                var t = '<tr><td width="3%"><img src="img/exp.png" /></td>'
                        + '<td width="80%"><a href="Javascript:void(0)" name="' + art_id
                        + '" class="newstitle" onclick="getTestRole(this)">' + art_title + '</a></td>'
                        + '<td width=7%;><span class="author">' + user_name + '</span></td>'
                        + '<td width=10%;><span class="ctime">' + time + '</span></td></tr>';
                $("#travelList").append(t);
            }
        }
    });

}

function tomodifyinfo() {

    var userid = $("#loguserid").val();
    var realname = $("#realname").val();
    var certnum = $("#certnum").val();
    var linkphone = $("#linkphone").val();
    var drivenum = $("#drivenum").val();
    var driveyear = $("#driveyear").val();
    console.log(realname, certnum, linkphone, drivenum, driveyear);
    if (realname == null) {
        alert("真实姓名不能为空");
        return;
    }
    if (certnum == null) {
        alert("证件信息不能为空");
        return;
    }
    if (linkphone == null) {
        alert("联系方式不能为空");
        return;
    }
    if (drivenum == null) {
        alert("驾驶证信息不能为空");
        return;
    }
    if (driveyear == null) {
        alert("驾龄不能为空");
        return;
    }
    $.ajax({
        url : "/DrivingMan/log/modifyInfo.do",
        type : "post",
        data : {
            "userid" : userid,
            "realname" : realname,
            "certnum" : certnum,
            "linkphone" : linkphone,
            "drivenum" : drivenum,
            "driveyear" : driveyear
        },
        dataType : "json",
        success : function(result) {

            if ("0000" == result.status) {
                alert(result.detail);
                var realname = result.data;
                $("#login-id").text(realname);
                close_perinfo();
                window.location.href("qryCar.html");
            }

        }
    });
}

function returncar(order_id) {

    var orderstatus = 1;
    var difdo = "";
    var orderid = order_id;
    console.log(orderstatus, difdo, orderid);
    $.ajax({
        url : "/DrivingMan/orderInfo/modifyOrderStatus.do",
        type : "post",
        data : {
            "orderstatus" : orderstatus,
            "difdo" : difdo,
            "orderid" : orderid
        },
        dataType : "json",
        success : function(result) {

            if (result.status == "0000") {
                alert(result.detail);
                $("#myorderbody").empty();
                loadOrder();
            }
        }
    });
}

function writetest(order_id) {

    var orderstatus = 2;
    var difdo = "";
    var orderid = order_id;
    window.open("carExp.html?orderid=" + orderid + "");
}

function getTestRole(a) {

    var $a = $(a);
    var artid = $a.attr("name");
    window.open("carExpDetail.html?artid=" + artid + "");
}